package ${package}.${moduleName}.${controllerName};

import ${package}.${moduleName}.${serviceName}.${className}Service;
import ${package}.${bottomName}.dto.req.${className}QueryReq;
import ${package}.${bottomName}.dto.req.${className}StoreReq;
import ${package}.${bottomName}.dto.resp.${className}Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import com.xiangxiang.commonlog.annotation.ActionLog;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.util.Assert;
import lombok.SneakyThrows;

/**
* ${classname}管理
* ${comments}
* @author ${author}
* @date ${datetime}
* 邮箱=-> ${email}
*/
@RestController
@RequestMapping("/${classname}")
@Api(tags = "${comments}管理")
@RequiredArgsConstructor
public class ${className}Controller{

    private final ${className}Service ${classname}Service;


    /**
    * 分页查询
    * @param entity 查询参数
    * @return 查询结果
    */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询${comments}", httpMethod = "POST",response = ${className}Resp.class)
    @ActionLog(module = "${comments}管理",actionType = "分页查询${comments}")
    public IPage<${className}Resp> page(@RequestBody ${className}QueryReq entity){
        Assert.notNull(entity,"参数不允许为空");
        return ${classname}Service.page(entity);
    }


    /**
    * 保存数据
    * @param entity 参数
    * @return 保存结果
    */
    @PostMapping("/insert")
    @ActionLog(module = "${comments}管理",actionType = "创建${comments}")
    @ApiOperation(value = "创建${comments}", httpMethod = "POST",response = Boolean.class)
    public Boolean insert(@ApiParam(name = "${comments}对象", value = "传入json格式", required = true) @RequestBody ${className}StoreReq entity) {
        Assert.notNull(entity,"参数不允许为空");
        return ${classname}Service.save(entity);
    }


    /**
    * 更新数据
    * @param entity 参数
    * @return 更新结果
    */
    @PostMapping("/update")
    @ActionLog(module = "${comments}管理",actionType = "更新${comments}")
    @ApiOperation(value = "更新${comments}", httpMethod = "POST",response = Boolean.class)
    public Boolean update(@ApiParam(name = "${comments}对象", value = "传入json格式", required = true)  @RequestBody ${className}StoreReq entity) {
        Assert.notNull(entity,"参数不允许为空");
        Assert.notNull(entity.get${pk.attrName}(),"主键不允许为空");
        return ${classname}Service.update(entity);
    }

    /**
    * 逻辑删除
    * @param  entity 参数
    * @return 删除结果
    */
    @PostMapping("/delete")
    @ActionLog(module = "${comments}管理",actionType = "删除${comments}")
    @ApiOperation(value = "删除${comments}", httpMethod = "POST",response = Boolean.class)
    public Boolean delete(@ApiParam(name = "${comments}对象", value = "传入json格式", required = true)  @RequestBody ${className}StoreReq entity) {
        Assert.notNull(entity,"参数不允许为空");
        Assert.notNull(entity.get${pk.attrName}(),"主键不允许为空");
        return ${classname}Service.delete(entity);
    }


    /**
    * 导出数据
    * @param response 响应结果
    * @param req 请求参数
    */
    @PostMapping("/export")
    @SneakyThrows
    @ApiOperation(value = "导出${comments}", httpMethod = "POST")
    @ActionLog(module = "${comments}管理",actionType = "导出${comments}")
    public void export(HttpServletResponse response, @RequestBody @ApiParam("${comments}") ${className}QueryReq req) {
         Assert.notNull(req,"参数不允许为空");
         ${classname}Service.export(response, req);
    }

}
